/**
 * 权限管理
 */
import {
  getRoleList,
  addRoleList,
  updateRoleList,
  delRoleList,
  searchTitle,
  addAdmin,
  getAdminList,
  delAdmin,
  updateAdmin,
  searchAccount,getIndexData,
  addMenus,getWebsiteList,addWebsite,deleteWebsite,updateWebsite,
  updateMenus, delMenus,searchMenusTitle,menusDelete,searchPidAndNotMenu
} from "@/api/admin";
import {getRouterList,getList} from "@/api/router"

const state = {roleList: null, adminList: null, menuList: null,websiteList:null};
const getters = {
  roleList: (state) => state.roleList,
  adminList: (state) => state.adminList,
  menuList: (state) => state.menuList,
  websiteList: (state) => state.websiteList,
};

const mutations = {
  setRoleList(state, data) {
    state.roleList = data;
  },
  setAdminList(state, data) {
    state.adminList = data;
  },
  setMenusList(state, data) {
    state.menuList = data;
  },
  setWebsiteList(state, data) {
    state.websiteList = data;
  },

};
const actions = {
  async setRoleList({commit}, param) {
    const {data} = await getRoleList(param);
    commit("setRoleList", data);
  },

  async addRoleList({commit}, param) {
    return await addRoleList(param);
  },

  async updateRoleList({commit}, data) {
    return await updateRoleList(data);
  },

  async delRoleList({commit}, data) {
    return await delRoleList(data);
  },

  async searchTitle({commit}, param) {
    const {data} = await searchTitle(param);
    commit("setRoleList", data);
  },

  async addAdmin({commit}, param) {
    return await addAdmin(param);
  },

  async setAdminList({commit}, param) {
    const {data} = await getAdminList(param);
    commit("setAdminList", data);
  },

  async delAdmin({commit}, param) {
    return await delAdmin(param);
  },

  async updateAdmin({commit}, param) {
    return await updateAdmin(param);
  },

  async searchAccount({commit}, param) {
    const {data} = await searchAccount(param);
    commit("setAdminList", data);
  },

  async addMenus({commit}, param) {
    return await addMenus(param);
  },

  async setMenusList({commit}, param) {
    const {data} = await getRouterList(param);
    commit("setMenusList", data);
  },
  async getList({commit}, param) {
    const {data} = await getList(param);
    commit("setMenusList", data);
  },
  async searchMenusTitle({commit}, param) {
    const {data} = await searchMenusTitle(param);
    commit("setMenusList", data);
  },
  async updateMenus({commit}, param) {
    return await updateMenus(param);
  },
  async delMenus({commit}, param) {
    return await delMenus(param);
  },
  async menusDelete({commit}, param) {
    return await menusDelete(param);
  },
  async searchPidAndNotMenu({commit}, param) {
    return await searchPidAndNotMenu(param);
  },

  async getWebsiteList({commit}, param) {
    const {data} = await getWebsiteList(param);
    commit("setWebsiteList", data);
  },

  async getIndexData({commit}, param) {
    return  await getIndexData(param);
  },

  async updateWebsite({commit}, param) {
    return await updateWebsite(param);
  },
  async addWebsite({commit}, param) {
    return await addWebsite(param);
  },
  async deleteWebsite({commit}, param) {
    return await deleteWebsite(param);
  },
};
export default {state, getters, mutations, actions};
